package sg.edu.nus.iss.vmcs.builder;

import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;

import sg.edu.nus.iss.vmcs.customer.CoinInputBox;
import sg.edu.nus.iss.vmcs.customer.CustomerPanel;
import sg.edu.nus.iss.vmcs.customer.DrinkSelectionBox;
import sg.edu.nus.iss.vmcs.customer.TerminateButtonListenser;
import sg.edu.nus.iss.vmcs.customer.TransactionController;
import sg.edu.nus.iss.vmcs.util.LabelledDisplay;
import sg.edu.nus.iss.vmcs.util.WarningDisplay;

/**
 * @version 1.0
 * @author Yeo Hee Ling
 */
public class CustomerUIBuilder extends UIBuilder {
	
	private TransactionController transactionController;
	private CustomerPanel custPanel;
	
	public CustomerUIBuilder(Frame frame, TransactionController transactionController) {
		this.transactionController = transactionController;
		custPanel = new CustomerPanel(frame, transactionController);
	}
	
	public void buildVendingNorthPanel () {
		Label lb = new Label("VIMTO Soft Drink Dispenser");
		lb.setFont(new Font("Helvetica", Font.BOLD, 24));
		Panel tp=new Panel();
		tp.add(lb);
		
		CoinInputBox coinInputBox = new CoinInputBox(transactionController.getCoinReceiver());
		custPanel.setCoinInputBox(coinInputBox);
		
		WarningDisplay invalidCoin = new WarningDisplay("Invalid Coin");
		custPanel.setInvalidCoinDisplay(invalidCoin);
		
		LabelledDisplay totalMoney = new LabelledDisplay("Total Money Inserted:", 10, LabelledDisplay.FLOW);
		totalMoney.setEditable(false);
		custPanel.setTotalMoneyDisplay(totalMoney);
				
		Panel coinInputPanel = new Panel(new GridLayout(0,1));
		coinInputPanel.add(coinInputBox);
		coinInputPanel.add(invalidCoin);
		coinInputPanel.add(totalMoney);

		Panel northPanel = new Panel(new BorderLayout());
		northPanel.add(BorderLayout.NORTH, tp);
		northPanel.add(BorderLayout.SOUTH, coinInputPanel);
		custPanel.add(BorderLayout.NORTH, northPanel);
	}
	
	public void buildVendingCenterPanel () {
		
	}
	
	public void buildVendingSouthPanel () {
		DrinkSelectionBox drinkSelectionBox = new DrinkSelectionBox(transactionController);
		custPanel.setDrinkSelectionBox(drinkSelectionBox);
		
		WarningDisplay noChange = new WarningDisplay("No/Less Change  Available");
		custPanel.setNoChangeDisplay(noChange);
		Panel pnlNoChange = new Panel(new FlowLayout());
		pnlNoChange.add(noChange);
		
		Button terminate = new Button("Terminate and Return Cash");
		terminate.addActionListener(new TerminateButtonListenser(transactionController));
		custPanel.setTerminateButton(terminate);
		Panel pnlTerminate = new Panel(new FlowLayout());
		pnlTerminate.add(terminate);
		
		LabelledDisplay collectCoin = new LabelledDisplay("Collect Coins:", 5,LabelledDisplay.FLOW);
		collectCoin.setEditable(false);
		custPanel.setCollectCoinDisplay(collectCoin);
		Panel pnlCollectCoin = new Panel(new FlowLayout());
		pnlCollectCoin.add(collectCoin);
		
		LabelledDisplay collectCan = new LabelledDisplay("Collect Can Here:", 5,LabelledDisplay.FLOW);
		collectCan.setEditable(false);
		custPanel.setCollectCanDisplay(collectCan);
		Panel pnlCollectCan = new Panel(new FlowLayout());
		pnlCollectCan.add(collectCan);
		
		Panel south = new Panel(new GridLayout(0,1));
		south.add(noChange);
		south.add(pnlTerminate);
		south.add(collectCoin);
		south.add(collectCan);
		
		Panel southPanel = new Panel(new BorderLayout());
		southPanel.add(BorderLayout.NORTH, drinkSelectionBox);
		southPanel.add(BorderLayout.CENTER, south);
		custPanel.add(BorderLayout.SOUTH, southPanel);
		custPanel.pack();
	}
	
	public CustomerPanel getResultPanel() {
		return this.custPanel;
	}
}
